package com.wang.service.impl;


import com.aaa.entity.TbBottomArticle;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wang.mapper.TbBottomArticleMapper;
import com.wang.service.TbBottomArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class TbBottomArticleServiceImpl extends ServiceImpl<TbBottomArticleMapper, TbBottomArticle>
        implements TbBottomArticleService {
    @Autowired
    private TbBottomArticleMapper tbBottomArticleMapper;

    @Override
    public Result Title() {
        List<TbBottomArticle> list = tbBottomArticleMapper.list();
        //使用jdk1.8进行父类进行使用分组进行分组
        Map<String, List<TbBottomArticle>> menuMap = list.stream().collect(Collectors.groupingBy(TbBottomArticle::getParentId));
        //对父类进行遍历
        for (TbBottomArticle titleVo : list)
         {
            //去拿到自己的id然后进行赋值,把父亲id；进行vule拿到如果他和父类相等这蛇者孩子
            List<TbBottomArticle> titleVos = menuMap.get(titleVo.getId());
            if (titleVos != null) {
                titleVo.setChildren(titleVos);
            }
        }
        return new Result(2000, "Success", list);
    }

}




